<template>
  <div>
    <div class="query">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="拼音">
          <el-input
            v-model="formInline.pinyin"
            placeholder="输入拼音"
          ></el-input>
        </el-form-item>
        <el-form-item label="药品名称">
          <el-input
            v-model="formInline.drugName"
            placeholder="输入药品名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="mainBody">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="id" label="id" width="50"> </el-table-column>
        <el-table-column prop="drugName" label="药品名称" width="120">
        </el-table-column>
        <el-table-column prop="specs" label="规格" width="120">
        </el-table-column>
        <el-table-column prop="unit" label="单位" width="120">
        </el-table-column>
        <el-table-column prop="num" label="数量" width="120"> </el-table-column>
        <el-table-column prop="price" label="价格" width="120">
        </el-table-column>
        <el-table-column prop="remarks" label="备注" width="120">
        </el-table-column>
        <el-table-column prop="functions" label="作用" width="120">
        </el-table-column>
        <el-table-column prop="origin" label="产地" width="120">
        </el-table-column>
        <el-table-column prop="type" label="类型" width="120">
        </el-table-column>
        <el-table-column prop="toxicity" label="毒性" width="120">
        </el-table-column>
        <el-table-column prop="degree" label="等级" width="120">
        </el-table-column>
        <el-table-column prop="kilogramPrice" label="公斤价" width="120">
        </el-table-column>
        <el-table-column prop="pricePerKilogram" label="单斤价" width="120">
        </el-table-column>
        <el-table-column prop="pricePerGram" label="克价" width="120">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >查看</el-button
            >
            <el-button type="text" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pageNum"
        :page-sizes="[10, 20, 30, 40, 50, 100]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { queryList } from "@/api/api.js";

export default {
  methods: {
    onSubmit() {
      this.queryList();
    },
    //分页按钮
    handleSizeChange(val) {
      console.log(val);
      this.queryList();
    },
    handleCurrentChange(val) {
      console.log(val);
      this.queryList();
    },
    //点击查看
    handleClick(row) {
      console.log(row);
    },
    //查询表格
    queryList() {
      let param = { ...this.formInline };
      //使用展开运算符复制source到param
      Object.assign(param, { ...this.page });
      queryList(param).then((res) => {
        if (res.status === 200) {
          this.tableData = res.data.list;
          this.page.pageNum = res.data.pageNum;
          this.page.pageSize = res.data.pageSize;
          this.page.total = res.data.total;
        }
      });
    },
  },

  data() {
    return {
      page: {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      },
      formInline: {
        pinyin: "",
        drugName: "",
      },
      tableData: [],
    };
  },
};
</script>